package com.xiaojun.whut.handle;

import com.alibaba.fastjson.JSON;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutHandler;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;

/**
 * @author 鲁佳磊
 * @create 2020-11-02 10:01
 */
public class MyLogoutHandler implements LogoutHandler {
    @Override
    public void logout(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) {
        httpServletResponse.setContentType("application/json;charset=utf-8");
        System.out.println("登出成功！！！！");
        PrintWriter out = null;
        try {
            out = httpServletResponse.getWriter();
        } catch (IOException e) {
            e.printStackTrace();
        }

        HashMap<String, Object> stringObjectHashMap = new HashMap<>();
        stringObjectHashMap.put("status",200);
        stringObjectHashMap.put("msg","登出成功");
        stringObjectHashMap.put("userInfo",authentication);

        out.write(JSON.toJSONString(stringObjectHashMap));
        out.flush();
        out.close();
    }
}
